package com.stone.framework.batch.config;

import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import com.stone.framework.batch.service.JdbcBatchService;

@Configuration
public class BatchConfig {

    @Bean
    public TaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize(30);
        taskExecutor.setMaxPoolSize(50);
        taskExecutor.setQueueCapacity(100);
        taskExecutor.setKeepAliveSeconds(600);
        taskExecutor.setThreadNamePrefix("stone-batch-task-");
        return taskExecutor;
    }

    @Bean
    public JdbcBatchService jdbcBatchService(DataSource dataSource) {
        JdbcBatchService batchService = new JdbcBatchService();
        batchService.setDataSource(dataSource);
        return batchService;
    }

}
